<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    {include file="common/head" /}
</head>

<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form action="" method="post" class="layui-form layui-form-pane">

            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">
                    拥有权限
                </label>
                <table  class="layui-table layui-input-block">
                    <tbody>
                    {volist name="list" id="vo"}
                    <tr>
                        <td>
                            <input type="checkbox" name="ids[]" {in name="vo['id']" value="$authList"}checked{/in} lay-skin="primary" lay-filter="father" value="{$vo.id}" title="{$vo.name}">
                        </td>
                        <td>
                            <table  class="layui-table layui-input-block">
                                <tbody>
                                {volist name="vo['child']" id="two"}
                                <tr>
                                    <td>
                                        <input type="checkbox" name="ids[]" {in name="two['id']" value="$authList"}checked{/in} lay-skin="primary" lay-filter="father" value="{$two.id}" title="{$two.name}">
                                    </td>
                                    <td>
                                        <table  class="layui-table layui-input-block">
                                            <tbody>
                                            {volist name="two['child']" id="three"}
                                            <tr>
                                                <td>
                                                    <input type="checkbox" name="ids[]" {in name="three['id']" value="$authList"}checked{/in} lay-skin="primary" lay-filter="father" value="{$three.id}" title="{$three.name}">
                                                </td>
                                                <td>
                                                    <div class="layui-input-block">
                                                        {volist name="three['child']" id="fore"}
                                                        <input name="ids[]" {in name="fore['id']" value="$authList"}checked{/in} lay-skin="primary" type="checkbox" title="{$fore.name}" value="{$fore.id}">
                                                        {/volist}
                                                    </div>
                                                </td>
                                            </tr>
                                            {/volist}
                                            </tbody>
                                        </table>
                                    </td>
                                </tr>
                                {/volist}
                                </tbody>
                            </table>
                        </td>
                    </tr>
                    {/volist}
                    </tbody>
                </table>
            </div>

            <div class="layui-form-item">
                <button class="layui-btn layui-btn-lg" lay-submit="" lay-filter="add">确 定</button>
            </div>
        </form>
    </div>
</div>
<script>
    layui.use(['form','layer'], function(){
        $ = layui.jquery;
        var form = layui.form
            ,layer = layui.layer;


        //监听提交
        form.on('submit(add)', function(data){
            $.ajax({
                type: "POST",
                url: "{:url('',['group_id'=>$gid])}",
                data: data.field,
                dataType:'json',
                success: function (result) {
                    if(result.code){
                        layer.alert(result.msg, {icon: 6},function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                        });
                    }else{
                        layer.alert(result.msg, {icon: 2},function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                        });
                    }
                },
                error: function(data) {
                    console.log(data);
                    layer.msg(data.msg,{icon:2,time:1000});
                }

            });
            return false;
        });


        form.on('checkbox(father)', function(data){

            if(data.elem.checked){
                $(data.elem).parent().siblings('td').find('input').prop("checked", true);
                form.render();
            }else{
                $(data.elem).parent().siblings('td').find('input').prop("checked", false);
                form.render();
            }
        });


    });
</script>

</body>

</html>